package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.*;
import com.ylyq.ylxx.model.request.*;
import com.ylyq.ylxx.service.IOceanegineCreativeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OceanengineCreativeController
 * @Description TODO
 * @Author xiaweichao
 * @Date 2020/7/1 11:35
 * @Version 1.0
 */
@RestController
@RequestMapping("/oCeanengine/creative")
@Api(description = "巨量引擎广告创意的相关接口")
public class OceanengineCreativeController {
    @Autowired
    private IOceanegineCreativeService iOceanegineCreativeService;

    @PostMapping("/getCreative")
    @ApiOperation(value = "获取广告创意列表",response = OceanengineCreativeInfo.class)
    public ResponseData getCreative(@Valid @RequestBody GetCreativeRequest getCreativeRequest) {
        return iOceanegineCreativeService.getCreative(getCreativeRequest);
    }

    @PostMapping("/creativeDetail")
    @ApiOperation(value = "获取广告创意详情",response = OceanengineCreativeDetail.class)
    public ResponseData creativeDetail(@Valid @RequestBody CreativeDetailRequest creativeDetailRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS,iOceanegineCreativeService.creativeDetail(creativeDetailRequest));
    }

    @PostMapping("/createCreative")
    @ApiOperation(value = "创建广告创意",response = OceanengineCreateCreativeResult.class)
    public ResponseData createCreative(@Valid @RequestBody List<CreateCreativeRequest> createCreativeRequest) {
        List<OceanengineCreateCreativeResult> results = new ArrayList<>();
        for (CreateCreativeRequest temp : createCreativeRequest) {
            OceanengineCreateCreativeResult creative = iOceanegineCreativeService.createCreative(temp);
            results.add(creative);
        }
        return new ResponseData(ResponseData.Result.SUCCESS,results);
    }

    @PostMapping("/updateCreative")
    @ApiOperation(value = "修改广告创意",response = OceanengineUpdateCreativeResult.class)
    public ResponseData updateCreative(@Valid @RequestBody List<UpdateCreativeRequest> updateCreativeRequests) {
        List<OceanengineUpdateCreativeResult> results = new ArrayList<>();
        for (UpdateCreativeRequest temp : updateCreativeRequests) {
            OceanengineUpdateCreativeResult creative = iOceanegineCreativeService.updateCreative(temp);
            results.add(creative);
        }
        return new ResponseData(ResponseData.Result.SUCCESS,results);
    }

    @PostMapping("/updateCreativeState")
    @ApiOperation(value = "更改创意状态",response = OceanengineUpdateCreativeState.class)
    public ResponseData updateCreativeState(@Valid @RequestBody UpdateCreativeState updateCreativeState) {
        return iOceanegineCreativeService.updateCreativeState(updateCreativeState);
    }

    @PostMapping("/creativematerialInfo")
    @ApiOperation(value = "创意素材信息",response = OceanengineCreativematerialInfo.class)
    public ResponseData creativematerialInfo(@Valid @RequestBody CreativematerialInfo creativematerialInfo) {
        return iOceanegineCreativeService.creativematerialInfo(creativematerialInfo);
    }

    @PostMapping("/creativeRejectreason")
    @ApiOperation(value = "获取创意审核建议",response = OceanengineCreativeRejectreason.class)
    public ResponseData creativeRejectreason(@Valid @RequestBody CreativeRejectreason creativematerialInfo) {
        return iOceanegineCreativeService.creativeRejectreason(creativematerialInfo);
    }

}
